package com.jinghang.hos.core.usermgr;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.UUID;


public class CoreUtil {
  public final static String SYSTEM_USER = "SuperAdmin";

  /**
   * 根据普通的字符串 ，返回加密后的字符串
   * @param str
   * @return
   */
  public static String getMd5Password(String str) {
    String reStr = null;
    try {
      MessageDigest md5 = MessageDigest.getInstance("MD5");
      byte[] bytes = md5.digest(str.getBytes());
      StringBuffer stringBuffer = new StringBuffer();
      for (byte b : bytes) {
        int bt = b & 0xff;
        if (bt < 16) {
          stringBuffer.append(0);
        }
        stringBuffer.append(Integer.toHexString(bt));
      }
      reStr = stringBuffer.toString();
    } catch (NoSuchAlgorithmException e) {
      e.printStackTrace();
    }
    return reStr;
  }

  public static String getUUID() {
    return UUID.randomUUID().toString().replace("-", "");
  }

  public static void main(String[] args) {
    System.out.println(getMd5Password("123456"));
    System.out.println(UUID.randomUUID().toString());
  }

}
